package com.example.a22310.myapplication.ViewModel.Train;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.Toast;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.NewBean;
import com.example.a22310.myapplication.Listener.TrainListener;
import com.example.a22310.myapplication.Model.TrainModel;
import com.example.a22310.myapplication.R;

import java.util.List;

public class ConsultViewModel implements TrainListener<NewBean> {
    private AppCompatActivity activity;
    private ActivityConsultBinding activityConsultBinding;



    public ConsultViewModel(AppCompatActivity activity,  ActivityConsultBinding activityConsultBinding,int clubid){
        this.activity = activity;
        this.activityConsultBinding = activityConsultBinding;
        activityConsultBinding.setNewBean(this);
        TrainModel trainModel=new TrainModel();
        trainModel.newsList(clubid,ConsultViewModel.this);
    }

    @Override
    public void onSuccess(List<NewBean> newBeen) {
        if(!newBeen.isEmpty()){
            activityConsultBinding.recyclerViewNews.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_news,
                    newBeen, BR.newBean);
            activityConsultBinding.recyclerViewNews.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败",Toast.LENGTH_LONG).show();
    }}
